package ca.cbc.giscommon.entity;

import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

@Entity
@Table(name = "zone")
public class Zone implements Cloneable, Serializable {

    private static final long serialVersionUID = 2906643503396010858L;
	private long id;
	private String name;
	private Geometry theGeom;
	
	public Zone() {}

	public Zone(String name, Geometry theGeom) {
		this.setName(name);
		this.setTheGeom(theGeom);
	}
	
	@Override
	public Zone clone() throws CloneNotSupportedException {
		return (Zone) super.clone();
	}
	
	public boolean equals(Object obj) {
		if(obj.getClass().equals(Zone.class) && ((Zone)obj).getId() == this.getId()) {
			return true;
		}
		return false;
	}
	
	@Id
	public long getId() {
		return id;
	}
	
	public String getName() {
		return name;
	}

	@Column(name = "the_geom")
	@Type(type = "org.hibernatespatial.GeometryUserType")
	public Geometry getTheGeom() {
		return theGeom;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
    public void setTheGeom(Geometry theGeom) {
		this.theGeom = theGeom;
	}
	
	public String toString() {
		return new StringBuffer("Zone {id:").append(id)
				.append(", name:").append(name)
				//.append(", theGeom:").append(theGeom)
				.append("}")
				.toString();
	}
}
